package com.flash.BusinessProcess.mapper;

import com.flash.BusinessProcess.entity.Settlement;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
public interface SettlementMapper {

    @Select("select * from (\n" +
            "select dbs.*,rownum rn from\n" +
            "(SELECT * FROM dealData d JOIN \n" +
            "(SELECT * FROM cash) sa ON d.cashId = sa.cashId JOIN \n" +
            "(SELECT * FROM security) se ON d.securityId  = se.securityId JOIN \n" +
            "(SELECT * FROM broker) b ON b.brokerId = d.brokerId where d.dealState=2 ${strWhere}) dbs)\n" +
            "WHERE rn between #{page} and #{limit}")
    List<Settlement> SettlementMap(Map map);

    @Select("select count(*) from dealData")
    int selectCountSettlement();


    @Select("select * from (\n" +
            "select dbs.*,rownum rn from\n" +
            "(SELECT * FROM dealData d JOIN \n" +
            "(SELECT * FROM cash) sa ON d.cashId = sa.cashId JOIN \n" +
            "(SELECT * FROM security) se ON d.securityId  = se.securityId JOIN \n" +
            "(SELECT * FROM broker) b ON b.brokerId = d.brokerId where d.dealState=1 ${strWhere}) dbs)\n" +
            "WHERE rn between #{page} and #{limit}")
    List<Settlement> SettlementMapFan(Map map);

    //1-2
    @Update("update dealData set dealState=2 where dealId = #{dealId}")
    int updateSettlement(String settlement);

    //2-1
    @Update("update dealData set dealState=1 where dealId = #{dealId}")
    int updateSettlementFan(String settlement);

}
